package com.zl.learning.lambada;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Test2 {

    public static class Test1 {
        public static void main(String[] args) {
            List<Integer> list = IntStream.rangeClosed(1, 10).boxed().collect(Collectors.toList());
            Runnable worker = () -> {
                try {
                    Thread.sleep(100);
                    list.stream().parallel().forEach(r -> System.out.println(Thread.currentThread().getName()));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            };
            new Thread(worker).start();
            new Thread(worker).start();
        }
    }

    public static class Test3 {
        public static void main(String[] args) throws ExecutionException, InterruptedException {
            List<Integer> list = IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList());
            ForkJoinPool pool = new ForkJoinPool(32);
            pool.submit(() -> list.stream().parallel().forEach(r -> System.out.println(Thread.currentThread().getName()))).get();

            Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {

            });
        }
    }

}
